package com.tanhua.server.contoller;

import com.tan.model.vo.PageResult;
import com.tanhua.server.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/comments")
public class CommentsCintroller {
    @Autowired
    private CommentService commentService;
    @PostMapping
    public ResponseEntity publishComment(@RequestBody Map map) {
      String movementId = (String)  map.get("movementId");
      String comment = (String)  map.get("comment");
      commentService.publishComment(movementId,comment);
      return ResponseEntity.ok(null);
    }
    @GetMapping
    public ResponseEntity<PageResult> getComments(String movementId, @RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "10") Integer pagesize){
       PageResult pageResult = commentService.getComments(movementId,page,pagesize);
       return ResponseEntity.ok(pageResult);
    }
    @GetMapping("/{id}/like")
    public ResponseEntity<Integer> getLikeCount(@PathVariable("id") String commentid){
        Integer count= commentService.getLikecommentCount(commentid);
        return ResponseEntity.ok(count);
    }
    @GetMapping("/{id}/dislike")
    public ResponseEntity<Integer> getdisLikeCount(@PathVariable("id") String commentid){
        Integer count= commentService.getdisLikecommentCount(commentid);
        return ResponseEntity.ok(count);
    }

}
